package com.ibiaoke.goods.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.GoodStockDao;
import com.ibiaoke.goods.dao.XcxShopPriceDao;
import com.ibiaoke.goods.entity.GoodStock;
import com.ibiaoke.goods.entity.XcxShopPrice;
import net.sf.ehcache.util.counter.sampled.SampledCounterImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class GoodStockServiceImpl implements  GoodStockService{

    @Autowired
    private GoodStockDao goodStockDao;

    @Autowired
    private XcxShopPriceDao xcxShopPriceDao;



    @Transactional
    @Override
    public Integer addGoodStock(String userName, Integer shopId,GoodStock goodStock) {

        AssertUtils.notNull(goodStock.getGoodId(), "商品id不能为空");
        AssertUtils.notNull(goodStock.getBuyTime(), "采购时间不能为空");

        goodStock.setOperator(userName);
        goodStock.setShopId(shopId);
        goodStock.setLeftoverNum(goodStock.getBuyNum());
        goodStock.setCreateTime(new Date());
        goodStockDao.insert(goodStock);
        xcxShopPriceDao.updateXcxGoodStockNum(goodStock.getGoodId(),shopId,goodStock.getBuyNum());
        return null;
    }

    @Override
    public List<GoodStock> findGoodStockList(String goodName, Integer id, Integer goodId,Date buyTime,
                                             Date buyEndTime,String supplier,String buyPro,String buyCity,Integer shopId,Page page) {
        return goodStockDao.findGoodStockList(goodName,id,goodId,buyTime,buyEndTime,supplier,buyPro,buyCity,shopId,page);
    }

}
